﻿using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using VisualPureBasicIDE.CoreGUI.Properties;

namespace VisualPureBasicIDE.CoreGUI
{
    [DefaultProperty("Icon")]
    class IconLabel : Panel
    {
        public enum Icons
        {
            Warning
        }

        private Icons _icon;
        private PictureBox _iconPictureBox;
        private readonly Label _label;

        [CategoryAttribute("General")]
        [Description("The icon of this IconLabel.")]
        public Icons Icon
        {
            get
            {
                return _icon;
            }
            set
            {
                _icon = value;

                if (_iconPictureBox == null)
                    _iconPictureBox = new PictureBox { Image = GetImage(_icon), Location = Point.Empty, Size = new Size(16, 16) };
                else
                    _iconPictureBox.Image = GetImage(_icon);
            }
        }

        [CategoryAttribute("General")]
        [Description("The text of this IconLabel.")]
        public string Description
        {
            get
            {
                return _label.Text;
            }
            set
            {
                _label.Text = value;
            }
        }

        public IconLabel(Icons icon)
        {
            Icon = icon;

            _label = new Label { Location = new Point(_iconPictureBox.Size.Width + 2, 2), Size = new Size(Width - 2, Height - 2), Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right};

            Controls.Add(_iconPictureBox);
            Controls.Add(_label);
        }

        public IconLabel() : this(Icons.Warning)
        {}

        private static Image GetImage(Icons icon)
        {
            switch (icon)
            {
                case Icons.Warning:
                    return Resources.warning_sign;
            }

            return null;
        }
    }
}